package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.mapper.entity.Question;
import com.example.demo.mapper.entity.QuestionBank;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Mapper
@Repository
public interface QuestionManageMapper extends BaseMapper<Question> {

    @Select("SELECT * FROM `question_bank` WHERE bank_id = #{bankId}")
    QuestionBank selectQuestionBankById(int bankId);

    @Update("UPDATE `question_bank` " +
            "SET question_count = #{questionCount} " +
            "WHERE bank_id = #{bankId}")
    int updateQuestionBank(QuestionBank nowBank);

    @Delete("<script>" +
            "DELETE FROM question" +
            " WHERE question_id IN" +
            " <foreach collection='list' index='index' open='(' separator=',' close=')' item='requestList' >" +
            "   #{requestList.questionId}" +
            " </foreach>" +
            "</script>")
    int batchDeleteQuestion(List<Question> requestList);
    @Update("UPDATE `question_bank` " +
            "SET question_count = question_count - 1 " +
            "WHERE bank_id = #{bankId}")
    int updateNowBank(int nowBankId);
    @Update("UPDATE `question_bank` " +
            "SET question_count = question_count + 1 " +
            "WHERE bank_id = #{bankId}")
    int updateNewBank(int newBankId);

}
